//
//  One22Cell.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 16/4/18.
//  Copyright © 2016年 sgone. All rights reserved.
//

#import "One22Cell.h"
#import "Common.h"
#define width1 136
#define rowHeight 28
@implementation One22Cell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = BACKGROUND1;
    
    if (self.view2 == nil)
    {
        self.view2 = [[UIView alloc]initWithFrame:CGRectMake(8, 8/FDLaOt, ViewWidth - 8*2, 141 / FDLaOt)];
        self.view2.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.view2];
        self.view2.layer.masksToBounds = YES;
        self.view2.layer.cornerRadius = 14.0f;
        self.view2.layer.borderColor = FDBCellColor.CGColor;
        self.view2.layer.borderWidth = 1.0f;
    }
    
    
    self.lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ViewWidth - 8*2, rowHeight/FDLaOt)];
    self.lbl1.backgroundColor = FDBCellColor;
    self.lbl1.textColor = [UIColor whiteColor];
    self.lbl1.textAlignment = NSTextAlignmentCenter;
    self.lbl1.font = [UIFont systemFontOfSize:14/FDLaOt];
    [self.view2 addSubview:self.lbl1];
    
//    for (int i = 0; i < 3; i++)
//    {
//        UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 35 /FDLaOt + rowHeight /FDLaOt+ rowHeight*i /FDLaOt  , ViewWidth - 8*2, 0.3)];
//        lbl.backgroundColor = [UIColor lightGrayColor];
//        [self.view2 addSubview:lbl];
//        
//    }
    
    
    
//    for (int i = 0; i < 4; i++) {
//        
//        UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(120,  44 /FDLaOt+ 12/FDLaOt  + rowHeight *i/FDLaOt, 0.4, 30/FDLaOt)];
//        lbl.backgroundColor = [UIColor lightGrayColor];
//        [self.view2 addSubview:lbl];
//    }
    
    
    for (int i = 0 ; i < 4; i++) {
        
        
        UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,  28 /FDLaOt  + rowHeight *i/FDLaOt, 120, rowHeight/FDLaOt)];
        lbl.backgroundColor = [UIColor clearColor];
        [self.view2 addSubview:lbl];
        lbl.font = [UIFont systemFontOfSize:14 / FDLaOt];
        lbl.textAlignment = NSTextAlignmentCenter;
//        lbl.textColor = [UIColor grayColor];

        switch (i) {
            case 0:
                
                lbl.text = @"订单编号";
                break;
            case 1:
                lbl.text = @"下单时间";
                break;
            case 2:
                
                lbl.text = @"运       费";
                break;
            case 3:
                lbl.text = @"总  金  额";
                break;
                
            default:
                break;
        }
    }
    
    
   
    
    if (self.lbl11 == nil) {
        
        self.lbl11 = [[UILabel alloc]initWithFrame:CGRectMake(width1, 8/FDLaOt + 28 /FDLaOt, ViewWidth - 124, rowHeight /FDLaOt)];
        self.lbl11.font = [UIFont systemFontOfSize:13 /FDLaOt];
        [self addSubview:self.lbl11];
    }
    
    
    if (self.lbl22 == nil) {
        
        self.lbl22 = [[UILabel alloc]initWithFrame:CGRectMake(width1,8/FDLaOt +  28/FDLaOt + rowHeight/FDLaOt, ViewWidth - 124, rowHeight/FDLaOt)];
        self.lbl22.font = [UIFont systemFontOfSize:13 /FDLaOt];
        [self addSubview:self.lbl22];
    }
    
    
 /*
    if (self.lbl33 == nil) {
        
        self.lbl33 = [[UILabel alloc]initWithFrame:CGRectMake(width1, 8/FDLaOt + 44/FDLaOt + 54*2 /FDLaOt, ViewWidth - 124, 27 /FDLaOt)];
        self.lbl33.font = [UIFont systemFontOfSize:13 /FDLaOt];
        [self addSubview:self.lbl33];
//        self.lbl33.backgroundColor = [UIColor greenColor];
        


    }
  */
    
    if (self.lbl34 == nil) {
        self.lbl34 = [[UILabel alloc]initWithFrame:CGRectMake(width1, 8/FDLaOt + 28/FDLaOt + rowHeight*2 /FDLaOt , ViewWidth - 124, rowHeight /FDLaOt)];
        self.lbl34.font = [UIFont systemFontOfSize:13 /FDLaOt];
        [self addSubview:self.lbl34];
//        self.lbl34.backgroundColor = [UIColor redColor];

    }
    
    
    
    if (self.lbl44 == nil) {
        self.lbl44 = [[UILabel alloc]initWithFrame:CGRectMake(width1,8/FDLaOt +  28/FDLaOt + rowHeight*3 /FDLaOt, ViewWidth - 124, rowHeight/FDLaOt)];
        self.lbl44.font = [UIFont systemFontOfSize:13 /FDLaOt];
        [self addSubview:self.lbl44];
        self.lbl44.textColor = BenSe_COLOR;
    }



    
    
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{

     NSString *ID = @"One22Cell";
    One22Cell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [[NSBundle mainBundle]loadNibNamed:@"One22Cell" owner:nil options:nil][0];
   
    }
    
 
    return cell;

}


-(void)loadCell:(NSDictionary *) dict
{
  
    
    
    
//    NSLog(@"dddddddd  %@",dict);
    
    
    if ([checkNull([dict objectForKey:@"dealer_name"]) length] > 0)
    {
        self.lbl1.text = [dict objectForKey:@"dealer_name"];
    }
    else
    {
        self.lbl1.text = @"";
    }
    
    

    self.lbl11.text = [dict objectForKey:@"order_id"];

    

    
    
    NSString *stringDate = [NSString stringWithFormat:@"%@",[dict objectForKey:@"order_time"]];
    int ordertime = [stringDate intValue];
    NSDate *orderdate = [[NSDate alloc]initWithTimeIntervalSince1970:ordertime];
    NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
    [formatter2 setDateFormat:@"yyy-MM-dd  HH:mm"];
    self.lbl22.text = [formatter2 stringFromDate:orderdate];
    
//    
//    
//    self.lbl33.text = [NSString stringWithFormat:@"总送货%d家(近%@家 远%@家)",[[dict objectForKey:@"far_num"]intValue ] +[[dict objectForKey:@"near_num"]intValue], [dict objectForKey:@"far_num"],[dict objectForKey:@"near_num"]];
    self.lbl34.text = [NSString stringWithFormat:@"%.2f元",[[dict objectForKey:@"amount_total"] floatValue] - [[dict objectForKey:@"product_amount"] floatValue]];
    self.lbl44.text = [NSString stringWithFormat:@"%.2f元",[[dict objectForKey:@"amount_total"] floatValue]];

}


- (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font

{
    
    CGRect rect = [string boundingRectWithSize:CGSizeMake(320, 54)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    
    return rect.size;
    
    
    
}

@end
